import com.alibaba.fastjson.JSON;

public class Proposer {
    public void invoke(Result result, Propose propose) {
        if (result.isPre()) {
            if (null != result.getPropose()) {
                int serialId = propose.getSerialId();
                propose = result.getPropose();
                propose.setSerialId(serialId);
                acceptPrepose(propose);
            } else {
                acceptPrepose(propose);
            }
        } else if (result.isAccept()) {
            return;
        } else {
            propose.incrementSerial();
            prePropose(propose);
        }
    }

    public void prePropose(Propose propose) {

    }

    public void acceptPrepose(Propose propose) {
        System.out.println("accept:" + JSON.toJSONString(propose));

    }

    public static void main(String[] args) {
        Result result = new Result();
        result.setStatus(1);
        result.setPropose(null);
        Propose propose = new Propose();
        propose.setName("test");
        propose.setValue("test");
        propose.setSerialId(1);

        Propose propose2 = new Propose();
        propose2.setName("test2");
        propose2.setValue("test2");
        propose2.setSerialId(2);
        result.setPropose(propose2);

        Proposer proposer = new Proposer();
        proposer.invoke(result, propose);
    }
}
